<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class QueryListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * @param QueryExecuted $event
     * @author 陈文小超
     * @maxim from专注to执行
     * @time 2021/3/24/11:33
     */
    public function handle(QueryExecuted $event)
    {
        //调试
        if (config('app.debug')) {
            $sql = str_replace("?", "'%s'", $event->sql);
            Log::debug(vsprintf($sql, $event->bindings));
        }
    }
}
